﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once

#include "GcmpDevService.h"

// 禁止有关STL无法导出的警告误报
#pragma warning( push )
#pragma warning( disable : 4251 )

namespace gcmp
{
    // GbmpString相当于StringBuilder和ostringstream
    class GCMP_DEV_SERVICE_EXPORT GbmpString 
    {
    public:
        GbmpString();
        GbmpString(const wchar_t* pStrW);
        GbmpString(const std::wstring& strW);

        // ！！注意！！ isNative只有和系统编码相关的转码操作才建议使用
        GbmpString(const char* pStr, bool isNative = true);
        GbmpString(const std::string& str, bool isNative = true);

    // 各种操作符重载
    public:
        GbmpString operator + (const GbmpString& _other) const;
        GbmpString& operator += (const GbmpString& _other);
        bool operator < (const GbmpString& _other) const { return getString() < _other.getString(); }
        bool operator == (const GbmpString& _other) const { return getString() == _other.getString(); }
        bool operator != (const GbmpString& _other) const { return getString() != _other.getString(); }
        GbmpString& operator << (const GbmpString& valString);
        GbmpString& operator << (int valInt);
        GbmpString& operator << (long long valInt64);
        GbmpString& operator << (double valDouble);

    // 与std::wstring对应的各种字符串操作
    public:
        static const int npos;
        static const GbmpString endl;
        bool empty() const { return getString().empty(); }
        int size() const { return (int)getString().size(); }
        int find(const GbmpString& _other, int pos) const { return (int)getString().find(_other.getString(), pos); }
        GbmpString substr(int pos, int n) const;

        GbmpString& assign(const GbmpString& _other);
        GbmpString& replace(int pos, int size, const GbmpString& newStr);
        void clear() { getStringFW().clear(); }

    // 自有操作
    public:
        void ReplaceSubString(const GbmpString& oldSubString, const GbmpString& newSubString);
        void RemoveQuotationMark();

    // 不同字符串的输出接口
    public:
        const std::wstring& getString() const { return m_theString; }
        std::wstring& getStringFW() { return m_theString; }
        const wchar_t* c_str() const { return getString().c_str(); }

    private:
        std::wstring m_theString;
    };
}

#pragma warning( pop )
